import React, { useState } from 'react'
import { Button, Input } from 'antd-mobile'
import request from '../../utils/request'
const App = () => {
	const [content, setContent] = useState('获取验证码')
	const [isDisable, setIsDisable] = useState(false)
	const CountDown = () => {
		let count = 60;
		setIsDisable(true)
		const time = setInterval(() => {
			count--
			setContent('倒计时' + count + '秒')

			if (count <= 0) {
				clearInterval(time);
				setContent('获取验证码')
				setIsDisable(false)
			}
		}, 1000)
	}

	const handleLogin = () => {
		request({
			url: '/api/login',
			method: 'post',
			data: {
				user: 'admin',
				pwd: 'admin'
			}
		}).then(resp => {
			localStorage.setItem('token', resp.data.token)
		})
	}
	return (
		<>
			<Input></Input>
			<Button block color='primary' onClick={() => CountDown()} disabled={isDisable}>{content}</Button>
			<button onClick={() => handleLogin()}>登录</button>
		</>
	)
}


export default App